﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class SpecialRecharge : System.Web.UI.Page
{
    int _id_SD;
    int id_MN;
    private ServiceBlo _serviceBlo = new ServiceBlo();
    private BillBlo _billBlo = new BillBlo();
    private BillDto _billDto = new BillDto();
    private MobileBlo _mobileBlo = new MobileBlo();    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            gdvSpecialRecharge.DataSource = _serviceBlo.SelectServiceActive("SpecialRecharge").ListServiceDetail;
            gdvSpecialRecharge.DataBind();
            lblError.Visible = false;
            panelDirect.Visible = false;
            panelOnline.Visible = false;
            panelPayment.Visible = false;
            panelPostBank.Visible = false;
            gdvSpecialRecharge.Visible = false;
            lblStatusStep1.Visible = false;
            lbtnStep2.Visible = false;
        }

    }
    protected void gdvSpecialRecharge_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {

        _id_SD = int.Parse(gdvSpecialRecharge.DataKeys[e.RowIndex].Value.ToString());
        lblError.Text = _id_SD.ToString();
        panelPayment.Visible = true;
        panelOnline.Visible = false;
        panelDirect.Visible = false;
        panelPostBank.Visible = false;
        gdvSpecialRecharge.Visible = false;
        txtMobile.Enabled = false;
        

    }
    protected int GetIDMobileNumber()
    {
        return _mobileBlo.SelectMobileByNumber(txtMobile.Text).Id_MN;
    }

    protected void btnOnline_Click(object sender, EventArgs e)
    {
        _id_SD = int.Parse(lblError.Text);
        lblError.Text = _id_SD.ToString();
        panelOnline.Visible = true;
        panelDirect.Visible = false;
        panelPostBank.Visible = false;

    }
    protected void btnPostBank_Click(object sender, EventArgs e)
    {
        panelOnline.Visible = false;
        panelDirect.Visible = false;
        panelPostBank.Visible = true;

    }
    protected void btnDirect_Click(object sender, EventArgs e)
    {
        panelOnline.Visible = false;
        panelDirect.Visible = true;
        panelPostBank.Visible = false;
    }
    protected void btnPayOnline_Click(object sender, EventArgs e)
    {
        _id_SD = int.Parse(lblError.Text);
        lblError.Text = _id_SD.ToString();
        id_MN = this.GetIDMobileNumber();
        _billDto = new BillDto(id_MN.ToString(), _id_SD.ToString(), DateTime.Now.ToShortDateString(),
                                       DateTime.Now.ToShortDateString(), true);
        _billBlo.InsertBill(_billDto);
        Response.Redirect("Bill.aspx");

    }
    protected void btnCheck_Click(object sender, EventArgs e)
    {

        id_MN = this.GetIDMobileNumber();
        if (id_MN == -1)
        {
            lblStatusStep1.ForeColor = Color.Red;
            lblStatusStep1.Text = "Your phone number is not valid";
            lblStatusStep1.Visible = true;
            panelPayment.Visible = false;
            btnCheck.Enabled = true;
            return;
        }
        lblStatusStep1.ForeColor = Color.BlueViolet;
        lblStatusStep1.Text = "Successful";
        lblStatusStep1.Visible = true;
        btnCheck.Enabled = false;
        txtMobile.Enabled = false;
        lbtnStep2.Visible = true;
        gdvSpecialRecharge.Visible = true;
    }
    protected void lbtnStep1_Click(object sender, EventArgs e)
    {
        txtMobile.Enabled = true;
        lblStatusStep1.Visible = false;
        btnCheck.Enabled = true;
        gdvSpecialRecharge.Visible = false;
        lblError.Visible = false;
        panelDirect.Visible = false;
        panelOnline.Visible = false;
        panelPayment.Visible = false;
        panelPostBank.Visible = false;
        lblStatusStep1.Visible = false;
        lbtnStep2.Visible = false;
    }
    protected void lbtnStep2_Click(object sender, EventArgs e)
    {
        lbtnStep2.Visible = true;
        panelDirect.Visible = false;
        panelOnline.Visible = false;
        panelPostBank.Visible = false;
        panelPayment.Visible = false;
        lblStatusStep1.Visible = false;
        lblError.Visible = false;
        gdvSpecialRecharge.Visible = true;
    }
    protected void btnPayPostBank_Click(object sender, EventArgs e)
    {
        _id_SD = int.Parse(lblError.Text);
        lblError.Text = _id_SD.ToString();
        id_MN = this.GetIDMobileNumber();
        _billDto = new BillDto(id_MN.ToString(), _id_SD.ToString(), DateTime.Now.ToShortDateString(),
                                        DateTime.Now.ToShortDateString(), false);
        _billBlo.InsertBill(_billDto);
        Response.Redirect("Bill.aspx");
    }
    protected void btnPayDirect_Click(object sender, EventArgs e)
    {
        _id_SD = int.Parse(lblError.Text);
        lblError.Text = _id_SD.ToString();
        id_MN = this.GetIDMobileNumber();
        _billDto = new BillDto(id_MN.ToString(), _id_SD.ToString(), DateTime.Now.ToShortDateString(),
                                        DateTime.Now.ToShortDateString(), false);
        _billBlo.InsertBill(_billDto);
        Response.Redirect("Bill.aspx");
    }
    
}